package com.itheima.domain;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.ArrayList;
import java.util.HashMap;

public class Test {
    public static void main(String[] args) throws JsonProcessingException {
        Student student = new Student("zhangsan", 12);
        Student student1 = new Student("lisi", 32);
        String s = new ObjectMapper().writeValueAsString(student);//{"name":"zhangsan","age":12}
        System.out.println(s);
        ArrayList<Student> arrayList = new ArrayList<Student>();
        arrayList.add(student);
        arrayList.add(student1);
        String s1 = new ObjectMapper().writeValueAsString(arrayList);//[{"name":"zhangsan","age":12},{"name":"lisi","age":32}]
        System.out.println(s1);
        HashMap<String, Integer> obHashMap = new HashMap<>();
        obHashMap.put("zhangsan",1);
        obHashMap.put("lisi",2);
        String s2 = new ObjectMapper().writeValueAsString(obHashMap);//{"lisi":2,"zhangsan":1}
        System.out.println(s2);

    }
}
